//
//  YLProgressView.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/11.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLProgressView.h"
#import <Masonry.h>

@interface YLProgressView ()
@property (nonatomic, weak) UIView *progressView;
@end

@implementation YLProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUp];
    }
    return self;
}

- (void)setUp
{
    self.backgroundColor = [UIColor whiteColor];
    
    __weak typeof(self) weakSelf = self;
    //进度
    UIView *progressView = [[UIView alloc] init];
    progressView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:progressView];
    [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.mas_equalTo(weakSelf);
        make.width.mas_equalTo(0);
    }];
    self.progressView = progressView;

}

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    
    [self layoutIfNeeded];
    
    __weak typeof(self) weakSelf = self;
    
    CGFloat width = self.frame.size.width * progress;
    [_progressView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
    }];
    
    [UIView animateWithDuration: 4 * progress animations:^{
        [weakSelf layoutIfNeeded];
    }];
}


@end
